package com.yunxun.amqp;

import com.google.gson.Gson;
import com.yunxun.entity.ArticleEntity;
import com.yunxun.entity.MessageEntity;
import com.yunxun.service.ArticleService;
import com.yunxun.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
public class RPCMethod {
    @Autowired
    private MessageService messageService;
    @Autowired
    private ArticleService articleService;
    public  String addOrder(String message) {
        try {
            if("messageQueue".equals(message)){
                MessageEntity messageEntity = new MessageEntity();
                messageEntity.setTypeValue(Integer.parseInt(message));
                List<MessageEntity> messageEntities = messageService.queryMessageByTypeValue(messageEntity);
                Gson gson = new Gson();
                String json = gson.toJson(messageEntities);
                return  json;
            }else {
                ArticleEntity articleEntity = new ArticleEntity();
                articleEntity.setMid(Integer.parseInt(message));
                articleEntity = articleService.selectByMid(articleEntity);
                Gson gson = new Gson();
                String json = gson.toJson(articleEntity);
                return json;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }
}
